package com.yanyu.space.codegen.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanyu.space.codegen.bean.po.TemplateGroup;
import com.yanyu.space.codegen.bean.vo.templateGroup.TemplateGroupSearchVo;
import com.yanyu.space.codegen.dao.AttrMapper;
import com.yanyu.space.codegen.dao.TemplateGroupMapper;
import com.yanyu.space.codegen.service.ITemplateGroupService;
import com.yanyu.space.common.core.bean.db.PageEntity;
import com.yanyu.space.common.db.pagination.PageUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 模板分组 服务实现类
 *
 * @author yanyu
 * @date 2020/11/18
 */
@Service
@AllArgsConstructor
public class TemplateGroupServiceImpl extends ServiceImpl<TemplateGroupMapper, TemplateGroup> implements ITemplateGroupService {

    private AttrMapper attrMapper;

    @Override
    public PageEntity<TemplateGroup> listPage(TemplateGroupSearchVo vo) {
        IPage<TemplateGroup> page = baseMapper.selectPage(PageUtil.getParam(), Wrappers.<TemplateGroup>lambdaQuery().orderByAsc(TemplateGroup::getSort));
        return PageUtil.getResult(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(TemplateGroup vo) {
        baseMapper.insert(vo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> ids) {
        ids.stream().forEach(id -> {
            baseMapper.deleteById(id);
        });
    }
}
